package algorithm;

import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

/**
 * Created by Administrator on 2017/7/11.
 */
public class  MyCollection<T> {
        final static int  FSIZE = 16;
        Object[] objects = new Object[FSIZE];
        int size ;
        public int getSize(){
            size= objects.length;
            return size;
        }
        public boolean isEmpty(){
            return objects.length<1;
        }

        public void makeEmpty(){
            objects = new Object[FSIZE];
        }

        public boolean insert(T obj){
            if (objects[objects.length-1]!=null){
                Object[] objects1 = new Object[3*FSIZE];
                objects1 = Arrays.copyOf(objects,objects1.length);
                objects = objects1;
            }

            for (int i = 0; i <objects.length ; i++) {
                if (objects[i]==null){
                    objects[i] = obj;
                    return true;
                }
            }
            return false;
        }

        public boolean remove(T obj){
            boolean success = false;
            for (int i = 0; i <objects.length ; i++) {
                if (obj.equals(objects[i])){
                    if (i==objects.length){
                        objects[i] = null;
                        success = true;
                        break;
                    }
                    for (int j = i; j <objects.length ; j++) {
                        objects[j] = objects[j+1];
                    }
                    objects[objects.length-1] = null;
                    success = true;
                    break;
                }
            }

            return success;
        }

    public void isPresent(T x){

    }

    @Override
    public boolean equals(Object obj) {//这边的equals没写好
        T t= (T)obj;

        return super.equals(obj);
    }

    private int compare(Comparator<T> com,T o1,T o2){
        return com.compare((T)o1,o2);
    }
}


